package com.yunxin.customui.service.executesqlimpl;

import cn.hutool.core.map.CaseInsensitiveMap;
import com.yunxin.customui.mapper.ExecuteMapper;
import com.yunxin.customui.myinterface.IExecuteSql;
import com.yunxin.customui.util.CustomSQLUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 *     卡片标签策略
 * date 2021/10/4 20:41
 *
 * Execute an SQL to return the value of a field
 * 执行一条SQL返回一个字段的值
 *
 * @author cc
 * @version 1.0
 */
@Service("ERR1")
//Execute Read Return One Value
public class ExecuteReadSQLReturnOneValue implements IExecuteSql<Object> {
    @Resource
    ExecuteMapper executeMapper;

    @Override
    public Object execute(String[] params, Map<String, Object> paramMap) {
        String sql = CustomSQLUtil.buildSQL(params[0], paramMap);
        List<CaseInsensitiveMap<String, Object>> caseInsensitiveMaps = executeMapper.executeReadSql(sql);
        if (caseInsensitiveMaps != null && caseInsensitiveMaps.size() != 0){
            return caseInsensitiveMaps.get(0).get(params[1]);
        }
        return new HashMap<>();
    }
}
